// 提取元素

// 1.提取头部元素
type ArrInfer01 = ['1', '2', 3, 4, 5];
// type First<T extends any[]> = T extends [infer one, infer two, infer three, infer four, infer five] ? one : [];
type First<T extends any[]> = T extends [infer one, ...any[]] ? one : [];
type aInfer = First<ArrInfer01> // '1'

/* 
infer的数量要与目标元素的个数一致，否则返回false的对应类型
type First<T extends any[]> = T extends [infer one, infer two, infer three] ? one : [];
type aInfer = First<ArrInfer01> // []
*/

// 2.提取尾部元素
type ArrInfer02 = ['1', '2', 3, 4, 5];
type Last<T extends any[]> = T extends [...any[], infer Last] ? Last : []
type bInfer = Last<ArrInfer02>

// 3.剔除尾部元素 pop
type ArrInfer03 = ['1', '2', 3, 4, 5];
type pop<T extends any[]> = T extends [...infer Rest, unknown] ? Rest : []
type cInfer = pop<ArrInfer03> // ['1', '2', 3, 4]

/* never 类型返回的是false的类型
type pop<T extends any[]> = T extends [...infer Rest, never] ? Rest : []
type cInfer = pop<ArrInfer03> // []
*/

// 4.剔除第一个元素 Shift
type ArrInfer04 = ['1', '2', 3, 4, 5];
type shift<T extends any[]> = T extends [unknown, ...infer Rest] ? Rest : []
type dInfer = shift<ArrInfer03> // ['2', 3, 4, 5]